<?php

namespace console\server;

use common\components\DoraRPC\TcpServer;

class YiduTcpServer extends TcpServer {

	private $app;

	function setApp($yii) {
		$this->app = $yii;
	}

	function initServer($server) {
		//the callback of the server init 附加服务初始化
		//such as swoole atomic table or buffer 可以放置swoole的计数器，table等
	}

	function doWork($param) {
		//process you logical 业务实际处理代码仍这里
		$api_name = $param['api']['name'];
		$action_param = $param['api']['param'];
		//log test
		$log_msg = "dowork runAction:" . $api_name . "  params:" . json_encode($action_param);
		\Yii::info($log_msg);

		//执行acontroller action 注意参数传递的是引用
		$this->app->runAction($api_name, [ & $action_param]);
		$result = $action_param['result'];
		$json_result = json_encode($result, JSON_UNESCAPED_UNICODE);
		\Yii::info("dowork result:" . $json_result);

		return $result;
	}

	function initTask($server, $worker_id) {
		//require_once() 你要加载的处理方法函数等 what's you want load (such as framework init)
	}

}
